package com.isoft.hospital.service.impl;

import com.isoft.hospital.common.ResponseData;
import com.isoft.hospital.dao.InhospitalDao;
import com.isoft.hospital.entity.Inhospital;
import com.isoft.hospital.service.InhospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InhospitalServiceImpl implements InhospitalService {
    @Autowired
    private InhospitalDao dao;

    @Override
    public ResponseData selectAll() {
        List<Inhospital> list = dao.selectAll();
        ResponseData responseData = new ResponseData();
        if (list != null) {
            responseData.setCode(0);
            responseData.setMsg("ok");
            responseData.setData(list);
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData insert(Inhospital inhospital) {
        int temp = dao.insert(inhospital);
        ResponseData responseData = new ResponseData();
        if (temp > 0) {
            responseData.setCode(0);
            responseData.setMsg("ok");
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData delete(int ba_id) {
        int temp = dao.delete(ba_id);
        ResponseData responseData = new ResponseData();
        if (temp > 0) {
            responseData.setCode(0);
            responseData.setMsg("ok");
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }

    @Override
    public ResponseData update(Inhospital inhospital) {
        int temp = dao.update(inhospital);
        ResponseData responseData = new ResponseData();
        if (temp > 0) {
            responseData.setCode(0);
            responseData.setMsg("ok");
        } else {
            responseData.setCode(1);
            responseData.setMsg("no");
        }
        return responseData;
    }
}

